package base;

import java.io.File;

public class LibraryApp {
	 public static void main(String[] args) {
	        try {
	            LibrarySystem lib = new LibrarySystem();

	            // 添加图书与读者
	            lib.addBook(new Book("978-7-123-45678-9", "Java编程思想", "Bruce Eckel", "机械工业出版社"));
	            lib.addBook(new Book("978-7-302-12345-6", "算法导论", "Thomas Cormen", "清华大学出版社"));
	            lib.addReader(new Reader("R001", "张三", "123456789"));
	            lib.addReader(new Reader("R002", "李四", "987654321"));

	            lib.showAllBooks();

	            // 借还测试
	            lib.borrowBook("R001", "978-7-123-45678-9");
	            lib.borrowBook("R002", "978-7-302-12345-6");

	            try {
	                lib.borrowBook("R001", "978-7-123-45678-9");
	            } catch (Exception ex) {
	                System.out.println("捕获业务异常（预期）：" + ex.getMessage());
	            }

	            lib.returnBook("R001", "978-7-123-45678-9");

	            try {
	                lib.returnBook("R001", "978-7-123-45678-9");
	            } catch (Exception ex) {
	                System.out.println("捕获业务异常（预期）：" + ex.getMessage());
	            }

	            System.out.println("\n内存借阅记录：");
	            lib.showAllRecords();

	            System.out.println("\n借阅记录文件路径：" + new File("borrow_records.txt").getAbsolutePath());

	        } catch (Exception e) {
	            System.out.println("运行时错误：" + e.getMessage());
	            e.printStackTrace();
	        }
	    }
}
